/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * <p>Project: app2022 - Test
 * <p>Powered by webrx On 2022-01-27 09:42:49
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Test {
    public static void main(String[] args) {
        //测试T3 实现Callable<> 接口，此多线程需要返回值
        T3 t3 = new T3(19);
        FutureTask<Integer> t = new FutureTask<>(t3);
        Thread tt = new Thread(t);
        tt.start();

        for (int i = 0; i < 3; i++) {
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(i);
        }

        try {
            //此处是线程计算结果，在没有完成是不返回，在此等
            System.out.println("计算完成，结果：" + t.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

    public static void t2(String[] args) {
        //测试T2线程类 实例化线程类
        T2 ta = new T2();
        T2 tb = new T2();
        T2 tc = new T2();

        //设置ta线程的名称
        ta.setName("TAA");
        //开启线程，（就绪状态）
        ta.start();

        tb.setName("TBB");
        tc.setName("TCC");
        tb.start();
        tc.start();

    }

    public static void t1(String[] args) {
        T1 t1 = new T1();
        Thread ta = new Thread(t1, "AA");
        Thread tb = new Thread(t1, "BB");
        ta.start();
        tb.start();
    }
}
